package com.zbj.data.jpa.datasource;

import org.apache.commons.lang.StringUtils;
import org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource;

/**
 * DynamicDataSource
 *
 * @author weigang
 * @create 2017-08-02
 **/
public class DynamicDataSource extends AbstractRoutingDataSource {
	@Override
	protected Object determineCurrentLookupKey() {
		//可以做一个简单的负载均衡策略JS
		String dataSource = DynamicDataSourceHolder.getDataSource();
		return StringUtils.isBlank(dataSource) ? DBType.MASTER : dataSource;
	}
}
